package com.pitaya.avatar.service.impl;

public class Distance implements Comparable<Distance>{
	
	protected Node startNode;
	protected Node endNode;
	protected double metric;
	
	public Distance(Node from, Node to){
		this.startNode = from;
		this.endNode = to;
		this.metric = this.computeMetric();
	}
	
	public int compareTo(Distance d) {
		double result = metric - d.metric;
		if(result<0)
			return -1;
		else 
			return 1;
	}
	
	protected double computeMetric(){
		double x = startNode.getXValue() - endNode.getXValue();
		double y = startNode.getYValue() - endNode.getYValue();
		return x*x + y*y;
	}
	
	public double getMetric(){
		return this.metric;
	}
	
	public Node getStartNode(){
		return this.startNode;
	}
	
	public Node getEndNode(){
		return this.endNode;
	}
	
}
